package com.by.component.tencent.cos;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.region.Region;
import com.by.component.tencent.TencentAccessProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Slf4j
@Configuration
public class TencentCosConfig {

    @Resource
    private TencentAccessProperties tencentAccessProperties;

    @Resource
    private TencentCosProperties tencentCosProperties;

    @Bean(destroyMethod = "shutdown")
    public COSClient initCosClient() {
        log.info("[TencentVodConfig][initCosClient] start");
        COSCredentials credentials = new BasicCOSCredentials(tencentAccessProperties.getSecretId(), tencentAccessProperties.getSecretKey());
        ClientConfig clientConfig = new ClientConfig(new Region(tencentCosProperties.getRegion()));
        return new COSClient(credentials, clientConfig);
    }

}
